<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<style type="text/css">
#changePassword table {
	width: 100%;
	text-align: center;
	padding-top: 100px;
}
#changePassword .title {
	text-align: right;
	padding-right: 10px
}
#changePassword .pwd {
	text-align: left;
}
#changePassword .button{
	text-align: left;
	padding-top: 10px;
}
#changePassword .button .submit{
	padding-left: 20px;
}
#changePassword .button .reset{
	padding-left: 20px;
}
</style>
<script type="text/javascript">
function resetPassword(){
	$('#changePassword').children().find('input').each(function(){
		$(this).val('');
	});
}

function changePassword(){
	$('#password_form').form({
		url : 'user/password.json',
		data: $('#password_form').serialize(),
		dataType: 'json',
		onSubmit : function() {
			var flag = $(this).form('validate');
			return flag;
		},
		success : function(data) {
			//console.log(data);
			//debugger;
			var json = JSON.parse(data);
			//console.log(json);
			if(json){
				if(json.code == 0){
					showInformationMessage('更新成功');
				}else if(json.code == 1001){
					showErrorMessage('密码错误');
				}else{
					showErrorMessage('更新失败');
				}
			}else{
				showErrorMessage('更新失败');
			}
		}
	});
	
	$('#password_form').submit();
}
</script>

<div id="changePassword" align="center">
<form id="password_form" method="post">
<input type="hidden" name="loginName" value="${userContext.user.loginName}"/>
<table>
	<tr>
		<th class="title">旧密码</th>
		<td class="pwd"><input type="password" name="oldPassword" class="easyui-validatebox" data-options="required:true,validType:'pwd'" maxlength="45"/></td>
	</tr>
	<tr>
		<th class="title">新密码</th>
		<td class="pwd"><input id="newPassword1" type="password" name="newPassword1" class="easyui-validatebox" data-options="required:true,validType:'pwd'" maxlength="45"/></td>
	</tr>
	<tr>
		<th class="title">确认新密码</th>
		<td class="pwd"><input type="password" name="newPassword" class="easyui-validatebox" data-options="required:true,validType:['equals[\'#newPassword1\']','pwd']" invalidMessage="两次输入的密码不一致" maxlength="45"/></td>
	</tr>
	<tr>
		<td></td>
		<td class="button">
			<span class="submit"><a href="javascript:void(0)" class="easyui-linkbutton" data-options="width:50" onclick="changePassword()">确认</a></span>
			<span class="reset"><a href="javascript:void(0)" class="easyui-linkbutton" data-options="width:50" onclick="resetPassword()">重置</a></span>
		</td>
	</tr>
</table>
</form>
</div>